package com.cxb.entity;

import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import com.cxb.utils.WifiUtils;

/**
 * Author jerry
 * date: 2016/8/6.
 */
public class AccessPoint implements Comparable<AccessPoint>{
	public String SSID;
	public int level;
	public WifiUtils.WifiCipherType cipherType;
	public String BSSID;
	public String pwd;

	@Override
	public int compareTo(AccessPoint accessPoint) {
		return accessPoint.level - this.level;
	}

	@Override
	public String toString() {
		return "[SSID="+SSID+",BSSID=" + BSSID+",cipherType="+cipherType.name()+",level="+level+"]";
	}

	public boolean isFree(){
		return cipherType == WifiUtils.WifiCipherType.WIFICIPHER_NOPASS;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof AccessPoint){
			AccessPoint other = (AccessPoint) obj;
			return SSID.equals(other.SSID) && BSSID.equals(other.BSSID);
		}
		return false;
	}

	public AccessPoint(WifiInfo info){
		SSID = info.getSSID().substring(1,info.getSSID().length()-1);
		BSSID = info.getBSSID();
		level = info.getRssi();
		cipherType = WifiUtils.getCipherTypeBySSID(SSID);
	}

	public AccessPoint(ScanResult scanResult){
		this.SSID = scanResult.SSID;
		this.level = scanResult.level;
		BSSID = scanResult.BSSID;
		this.cipherType = WifiUtils.getWifiCipher(scanResult.capabilities);
	}

	public AccessPoint(AccessPoint accessPoint){
		this.SSID = accessPoint.SSID;
		this.level = accessPoint.level;
		BSSID = accessPoint.BSSID;
		this.cipherType = accessPoint.cipherType;
	}

	public void setPwd(String pwd){
		this.pwd = pwd;
	}
}
